package com.micro.client;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 消息服务客户端
 */
@FeignClient(name = "message-service", fallback = MessageServiceClientFallback.class)
public interface MessageServiceClient {

    /**
     * 发送订单通知
     */
    @PostMapping("/api/message/order-notification")
    boolean sendOrderNotification(
        @RequestParam("userId") Long userId,
        @RequestParam("orderType") String orderType,
        @RequestParam("orderId") Long orderId,
        @RequestParam("title") String title,
        @RequestParam("content") String content
    );

    /**
     * 发送系统消息
     */
    @PostMapping("/api/message/system")
    boolean sendSystemMessage(
        @RequestParam("userId") Long userId,
        @RequestParam("title") String title,
        @RequestParam("content") String content
    );

    /**
     * 获取用户消息列表
     */
    @GetMapping("/api/message/user/{userId}")
    List<MessageDTO> getUserMessages(@PathVariable("userId") Long userId);

    /**
     * 消息DTO
     */
    class MessageDTO {
        private Long messageId;
        private Long userId;
        private String title;
        private String content;
        private String messageType;
        private Boolean isRead;
        private String createTime;

        // Getter和Setter方法
        public Long getMessageId() {
            return messageId;
        }

        public void setMessageId(Long messageId) {
            this.messageId = messageId;
        }

        public Long getUserId() {
            return userId;
        }

        public void setUserId(Long userId) {
            this.userId = userId;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }

        public String getMessageType() {
            return messageType;
        }

        public void setMessageType(String messageType) {
            this.messageType = messageType;
        }

        public Boolean getIsRead() {
            return isRead;
        }

        public void setIsRead(Boolean isRead) {
            this.isRead = isRead;
        }

        public String getCreateTime() {
            return createTime;
        }

        public void setCreateTime(String createTime) {
            this.createTime = createTime;
        }
    }
}

/**
 * 消息服务客户端降级处理
 */
class MessageServiceClientFallback implements MessageServiceClient {

    @Override
    public boolean sendOrderNotification(Long userId, String orderType, Long orderId, String title, String content) {
        return false;
    }

    @Override
    public boolean sendSystemMessage(Long userId, String title, String content) {
        return false;
    }

    @Override
    public List<MessageDTO> getUserMessages(Long userId) {
        return null;
    }
}
